package com.hsnn.medstgmini.base.std.controller;

import java.io.BufferedOutputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hsnn.medstgmini.Constants;
import com.hsnn.medstgmini.base.std.model.BidDrugcatas;
import com.hsnn.medstgmini.base.std.model.BidDrugcatasLog;
import com.hsnn.medstgmini.base.std.model.StdDrugQualitySpecLog;
import com.hsnn.medstgmini.base.std.model.StdDrugcatalog;
import com.hsnn.medstgmini.base.std.model.StdDrugcatalogLog;
import com.hsnn.medstgmini.base.std.service.StdDrugcatalogManager;
import com.hsnn.medstgmini.sys.model.SysUser;
import com.hsnn.medstgmini.util.AccountUtil;
import com.hsnn.medstgmini.util.DateUtil;
import com.hsnn.medstgmini.util.DbUtil;
import com.hsnn.medstgmini.util.ExcelUtil;
import com.hsnn.medstgmini.util.Pagination;
import com.hsnn.medstgmini.util.ParseNumber;
import com.hsnn.medstgmini.util.form.LogDetailForm;

@Controller
@RequestMapping( "/stdDrugcatalog" )
public class StdDrugcatalogController {
	@Autowired
	private StdDrugcatalogManager stdDrugcatalogManager;
	@Autowired
	private HttpServletRequest request;
	
	private static final Logger log = Logger.getLogger(StdDrugcatalogController.class);

	@RequestMapping( "/list" )
	public String toDrugcatalogList()
	{
		return("/base/std/drugcata/stdDrugcatalogList");
	}

	/**
	 * @category 查询药物目录
	 * @author 应晓川
	 * @date 2015年8月18日12:45:47
	 * @return
	 * @return Pagination
	 */
	@RequestMapping( "/getStdDrugcatalogData" )
	@ResponseBody
	public Pagination getStdDrugcatalogData()
	{
		Pagination page = new Pagination( request );
		DbUtil.jsonToMap( request, page );
		return stdDrugcatalogManager.getStdDrugcatalogList( page ) ;
	}

	/**
	 * @category 新增/修改药物目录
	 * @author 应晓川
	 * @date 2015年8月18日12:57:36
	 * @return
	 * @return Pagination
	 */
	@RequestMapping(value={"/add","/edit"})
	@ResponseBody
	public Pagination saveOrUpdateStdDrugcatalog( StdDrugcatalog stdDrugcatalog )
	{
		log.info(stdDrugcatalog.toString());
		Pagination page	= new Pagination( request );
		SysUser	user = (SysUser) request.getSession().getAttribute( Constants.USERINFO );
		String drugcatalogIdStr = request.getParameter( "drugcatalogIdStr" );
		try {
			List<StdDrugcatalog> list = stdDrugcatalogManager.getStdDrugcatalogByName( stdDrugcatalog.getDrugcatalogName());
			List<LogDetailForm> detailList = new ArrayList<LogDetailForm>();
			LogDetailForm form = null;
			if ( StringUtils.isNotBlank( drugcatalogIdStr ) ){
						StdDrugcatalog stdDrugcatalogFromDb = (StdDrugcatalog) stdDrugcatalogManager.getUniquerResult( StdDrugcatalog.class, "drugcatalogId",drugcatalogIdStr);				
						if(stdDrugcatalogFromDb!=null){
							if(list.size() ==0 || list.get(0).getDrugcatalogId().equals(stdDrugcatalogFromDb.getDrugcatalogId())){
								   	String drugcatalogName = stdDrugcatalogFromDb.getDrugcatalogName();//药物目录名称
								   	String startTime = DateUtil.date(stdDrugcatalogFromDb.getStartTime()) ;//启用日期
									String endTime = DateUtil.date(stdDrugcatalogFromDb.getEndTime());//停用日期
									short attribute =  stdDrugcatalogFromDb.getAttribute();//类型
									boolean tag =false;
									if(!(drugcatalogName.equals(stdDrugcatalog.getDrugcatalogName()))){
										stdDrugcatalogFromDb.setDrugcatalogName( stdDrugcatalog.getDrugcatalogName() );
										tag=true;
										form = new LogDetailForm();
										form.setColName("药物目录名称");
										form.setNewValue(stdDrugcatalog.getDrugcatalogName());
										form.setOldValue(drugcatalogName);
										detailList.add(form);
									}
									if(DateUtil.parseDate(startTime).getTime()!=DateUtil.parseDate( stdDrugcatalog.getStartTimeStr()).getTime()){
										stdDrugcatalogFromDb.setStartTime( DateUtil.parseDate( stdDrugcatalog.getStartTimeStr() ) );
										tag=true;
										form = new LogDetailForm();
										form.setColName("启用日期");
										form.setNewValue(stdDrugcatalog.getStartTimeStr());
										form.setOldValue(startTime);
										detailList.add(form);
									}
									if(DateUtil.parseDate(endTime).getTime()!=DateUtil.parseDate( stdDrugcatalog.getEndTimeStr()).getTime()){
										stdDrugcatalogFromDb.setEndTime( DateUtil.parseDate( stdDrugcatalog.getEndTimeStr() ) );
										tag=true;
										form = new LogDetailForm();
										form.setColName("停用日期");
										form.setNewValue(stdDrugcatalog.getEndTimeStr());
										form.setOldValue(endTime);
										detailList.add(form);
									}
									short attributeStr = ParseNumber.toShort( stdDrugcatalog.getAttributeStr());
									if( attribute != attributeStr){
										stdDrugcatalogFromDb.setAttribute(ParseNumber.toShort( stdDrugcatalog.getAttributeStr()));
										tag=true;
										form = new LogDetailForm();
										form.setColName("类型");
										form.setNewValue(attributeStr==0?"国家目录":(attributeStr==1?"省增补目录":""));
										form.setOldValue(attribute==0?"国家目录":(attribute==1?"省增补目录":""));
										detailList.add(form);
									}
									if(tag){
										stdDrugcatalogFromDb.setUpdDatetime(new Date());
										stdDrugcatalogFromDb.setUpdUser( user.getId() );
										stdDrugcatalogManager.update( stdDrugcatalogFromDb );
										StdDrugcatalogLog stdDrugcatalogLog = new StdDrugcatalogLog();
										BeanUtils.copyProperties( stdDrugcatalogLog,stdDrugcatalogFromDb );
										stdDrugcatalogLog.setLogId(UUID.randomUUID().toString());
										StringBuffer temp =new StringBuffer();
										for(LogDetailForm ldf :detailList){
											temp.append(ldf.getColName()+":&nbsp;由"+ldf.getOldValue()+"变为"+ldf.getNewValue()+"<br/>");
										}
										stdDrugcatalogLog.setDetail(temp.toString()); 
										stdDrugcatalogManager.save( stdDrugcatalogLog );
									}
									page.setSuccess( true );	
							}else{
							}
						}
			}else{
				 if ( list.size() == 0 )//名称未重名
				{
					
					
					stdDrugcatalog.setStartTime( DateUtil.parseDate( stdDrugcatalog.getStartTimeStr() ) );
					stdDrugcatalog.setEndTime( DateUtil.parseDate( stdDrugcatalog.getEndTimeStr() ) );
					stdDrugcatalog.setAttribute( ParseNumber.toShort( stdDrugcatalog.getAttributeStr() ) );
					stdDrugcatalog.setDrugcatalogId( UUID.randomUUID().toString() );
					
					if(StringUtils.isBlank(stdDrugcatalog.getDrugcatalogCode())){//新增编码
						stdDrugcatalog.setDrugcatalogCode(AccountUtil.getStdSequence(Constants.STD_YAOWUMULU_PREFIX, Constants.STD_YAOWUMULU, Constants.STD_YAOWUMULU_LEN));
					}

					stdDrugcatalog.setStatus( Constants.STD_DRUGCATALOG_status_1 );
					stdDrugcatalog.setUpdDatetime( new Date() );
					stdDrugcatalog.setUpdUser( user.getId() );
					stdDrugcatalogManager.save( stdDrugcatalog );
					StdDrugcatalogLog stdDrugcatalogLog = new StdDrugcatalogLog();
					BeanUtils.copyProperties( stdDrugcatalogLog,stdDrugcatalog );
					stdDrugcatalogLog.setLogId(UUID.randomUUID().toString());
					
					
					form = new LogDetailForm();
					form.setColName("药物目录编码");
					form.setNewValue(stdDrugcatalog.getDrugcatalogCode());
					detailList.add(form);
					
					form = new LogDetailForm();
					form.setColName("药物目录名称");
					form.setNewValue(stdDrugcatalog.getDrugcatalogName());
					detailList.add(form);
					
					form = new LogDetailForm();
					form.setColName("启用日期");
					form.setNewValue(stdDrugcatalog.getStartTimeStr());
					detailList.add(form);
					
					form = new LogDetailForm();
					form.setColName("停用日期");
					form.setNewValue(stdDrugcatalog.getEndTimeStr());
					detailList.add(form);
					
					form = new LogDetailForm();
					form.setColName("类型");
					form.setNewValue(stdDrugcatalog.getAttribute()==0?"国家目录":(stdDrugcatalog.getAttribute()==1?"省增补目录":""));
					detailList.add(form);
					
					
					StringBuffer temp =new StringBuffer("新增数据：<br/>");
					for(LogDetailForm ldf :detailList){
						temp.append(ldf.getColName()+":"+ldf.getNewValue()+"<br/>");
					}
					
					stdDrugcatalogLog.setDetail(temp.toString());
					
					stdDrugcatalogManager.save(stdDrugcatalogLog);
					page.setSuccess( true );
					page.setMsg(stdDrugcatalog.getDrugcatalogCode());
				}
			}
		} catch ( Exception e ) {
			e.printStackTrace();
			page.setSuccess( false );
		}
		return(page);
	}
	
	
	/**
	 * @category 批量停用启用
	 * @author 应晓川
	 * @date 2015年8月19日09:15:45
	 * @return
	 * @return Pagination
	 */
	@RequestMapping(value={"/enable","/disable"})
	@ResponseBody
	public Pagination updateStdDrugcatalogStatus(String param,String state){
		log.info("param="+param+",state="+state);
		Pagination page = new Pagination(request);
		SysUser	user = (SysUser) request.getSession().getAttribute( Constants.USERINFO );
		try {
			if (StringUtils.isNotBlank(param)) {
				page.getConditions().put("array", param);
			}
			if (StringUtils.isNotBlank(state)) {
				page.getConditions().put("status", state);		
			}
			page.getConditions().put("userId",user.getId());
			stdDrugcatalogManager.updateStatus(page);
			page.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
		}
		return page;
	}
	
	/**
	 * @category 去查看药物目录详情
	 * @author 应晓川
	 * @date 2015年8月19日08:41:15
	 * @return
	 * @return Pagination
	 */
	@RequestMapping( "/toStdDrugcatalogDetailInfo" )
	public String toStdDrugcatalogDetailInfo()
	{
		request.setAttribute("drugcatalogId", request.getParameter("drugcatalogId"));
		try {
			String drugcatalogName = new String(request.getParameter("drugcatalogName").getBytes("iso8859-1"),"utf-8");
			request.setAttribute("fileName", drugcatalogName+".xls");
			request.setAttribute("Name", drugcatalogName);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return("/base/std/drugcata/stdDrugcatalogDetailInfo");
	}
	
	/**
	 * @category 获取药物目录详情数据
	 * @author 应晓川
	 * @date 2015年8月19日08:41:15
	 * @return
	 * @return Pagination
	 */
	@RequestMapping( "/getStdDrugcatalogDetailInfo" )
	@ResponseBody
	public Pagination getStdDrugcatalogDetailInfo(){
		Pagination page = new Pagination(request);
		try {
			DbUtil.jsonToMap(request, page);
			page.getConditions().put("drugcatalogId", request.getParameter("drugcatalogId")) ;
			page = stdDrugcatalogManager.getStdDrugcatalogDetailInfo(page);
			page.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
		}
		return page;
	}
	
	/**
	 * @category 去添加明细
	 * @author 应晓川
	 * @date 2015年8月19日08:41:15
	 * @return
	 * @return Pagination
	 */
	@RequestMapping( "/toStdDrugcatalogDetailInfoAdd" )
	public String toStdDrugcatalogDetailInfoAdd()
	{
		request.setAttribute("drugcatalogId", request.getParameter("drugcatalogId"));
		try {
			String drugcatalogName = new String(request.getParameter("drugcatalogName").getBytes("iso8859-1"),"utf-8");
			request.setAttribute("fileName", drugcatalogName+".xls");
			request.setAttribute("Name", drugcatalogName);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return "/base/std/drugcata/stdDrugcatalogDetailInfoAdd";
	}
	
	/**
	 * @category 获取未关联药物目录的品规数据
	 * @author 应晓川
	 * @date 2015年8月19日08:49:53
	 * @return
	 * @return Pagination
	 */
	@RequestMapping( "/getStdDrugcatalogDetailInfoAdd" )
	@ResponseBody
	public Pagination getStdDrugcatalogDetailInfoAdd( ){
		Pagination page	= new Pagination( request );
	
		try {
			DbUtil.jsonToMap(request, page);
			page.getConditions().put("drugcatalogId", request.getParameter("drugcatalogId")) ;
			page = stdDrugcatalogManager.getStdDrugcatalogDetailInfoAdd(page);	
			page.setSuccess(true);
			
			
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
		}	
		return page;
	}
	/**
	 * @category 添加明细
	 * @author 应晓川
	 * @date 2015年8月19日14:08:52
	 * @return
	 * @return Pagination
	 */
	@RequestMapping( "/addStdDrugcatalogDetailInfo" )
	@ResponseBody
	public Pagination addStdDrugcatalogDetailInfo(BidDrugcatas bidDrugcatas){
		Pagination page	= new Pagination( request );
		SysUser	user = (SysUser) request.getSession().getAttribute( Constants.USERINFO );
		try {
			if (StringUtils.isNotBlank(bidDrugcatas.getQualityspecIndexStr())){
				bidDrugcatas.setQualityspecIndex(ParseNumber.toShort(bidDrugcatas.getQualityspecIndexStr()));
			}
			if(bidDrugcatas.getQualityspecIndexStr().trim().equals("")){
				bidDrugcatas.setQualityspecIndex(null);
			}
			bidDrugcatas.setStatus(Constants.STD_DRUGCATALOG_status_1);
			bidDrugcatas.setUpdDatetime(new Date());
			bidDrugcatas.setUpdUser(user.getId());
			bidDrugcatas.setDrugCataId(UUID.randomUUID().toString());
			stdDrugcatalogManager.save(bidDrugcatas);
			BidDrugcatasLog bidDrugcatasLog = new BidDrugcatasLog();
			BeanUtils.copyProperties( bidDrugcatasLog,bidDrugcatas );
			bidDrugcatasLog.setLogId(UUID.randomUUID().toString());
			stdDrugcatalogManager.save(bidDrugcatasLog);
			page.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
		}	
		return page;
	}
	
	/**
	 * @category 去查看药物目录维护记录详情
	 * @author 应晓川
	 * @date 2015年8月19日08:41:15
	 * @return
	 * @return Pagination
	 * @throws UnsupportedEncodingException 
	 */
	@RequestMapping( "/toStdDrugcatalogLogDetailInfo" )
	public String toStdDrugcatalogLogDetailInfo(String drugcatalogId,String code,String name) throws UnsupportedEncodingException
	{
		String temp = new String(name.getBytes("ISO8859-1"),"utf-8");
		request.setAttribute("drugcatalogId", drugcatalogId);
		request.setAttribute("code", code);
		request.setAttribute("name", temp);
		return "/base/std/drugcata/stdDrugcatalogLogDetailInfo";
	}
	
	/**
	 * @category 获取药物目录维护记录数据
	 * @author 应晓川
	 * @date 2015年8月19日08:46:23
	 * @return
	 * @return Pagination
	 */
	@RequestMapping( "/getStdDrugcatalogLogDetailInfo" )
	@ResponseBody
	public Pagination getStdDrugcatalogLogDetailInfo( ){
		Pagination page	= new Pagination( request );
		String drugcatalogId =  request.getParameter("drugcatalogId");
		String startDate =  request.getParameter("startDate");
		String endDate =  request.getParameter("endDate");
		try {
			page.getConditions().put("drugcatalogId",drugcatalogId);
			if(StringUtils.isNotBlank(startDate)){
				page.getConditions().put("startDate",startDate);
			}
			if(StringUtils.isNotBlank(endDate)){
				page.getConditions().put("endDate",endDate);		
			}
			stdDrugcatalogManager.getStdDrugcatalogLogList( page ) ;
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
		}	
		return page;
	}
	
	/**
	 * 
	 *@category 获取参数打印
	 *@author 徐国鹏
	 *@date 2015年6月9日
	 *Pagination
	 */
	@SuppressWarnings("rawtypes")
	public void printParams(){
		Enumeration paramNames = request.getParameterNames();
		try {
			while (paramNames.hasMoreElements()) {
				String paramName = (String) paramNames.nextElement();
				String paramValue = request.getParameter(paramName);
				log.info(paramName+":"+paramValue);
			}
		} catch (Exception e) {
			log.error("",e);
		}
	}
	
	
	/**
	 * @category 去查看药物目录维护记录对比
	 * @author 应晓川
	 * @date 2015年8月29日13:13:58
	 * @return
	 * @return Pagination
	 */
	@RequestMapping( "/toCompareStdDrugcatalogLog")
	/*	public String toCompareStdDrugcatalogLog(String logId){
		try {
			StdDrugcatalogLog stdDrugcatalogLog =  (StdDrugcatalogLog) stdDrugcatalogManager.getUniquerResult(StdDrugcatalogLog.class,"logId",logId);
			stdDrugcatalogLog.setUpdUser(stdDrugcatalogManager.getNameByUpdUser(stdDrugcatalogLog.getUpdUser()));
			
			StdDrugcatalogLog stdDrugcatalogLogHistory =  stdDrugcatalogManager.compareStdDrugcatalogLog(stdDrugcatalogLog);
			if(stdDrugcatalogLogHistory!=null){
				stdDrugcatalogLogHistory.setUpdUser(stdDrugcatalogManager.getNameByUpdUser(stdDrugcatalogLogHistory.getUpdUser()));	
			}
			request.setAttribute("stdDrugcatalogLog", stdDrugcatalogLog);
			request.setAttribute("stdDrugcatalogLogHistory", stdDrugcatalogLogHistory);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "/base/std/drugcata/stdDrugcatalogLogCompare";
	}*/
	
	public String  toStdDrugQualitySpecLogDetail(Model model, StdDrugcatalogLog stdDrugcatalogLog) {
		printParams();
		List<Map<String,Object>> list1 = stdDrugcatalogManager.getStdDrugcatalogLogDetail(stdDrugcatalogLog);
		List<Map<String,Object>> list = stdDrugcatalogManager.getStdDrugcatalogLogDetail(stdDrugcatalogLog);
		
		List<Map<String,Object>> dataList = new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> mapList = new ArrayList<Map<String,Object>>();
		String[] cColunm = {"药品目录编码","药品目录名称","启用日期","停用日期","类型","状态"};
		String[] eColunm = {"drugcatalogCode","drugcatalogName","startTime","endTime","attribute","status"};
		for(int i = 0;i<cColunm.length;i++){
			if(list1.size()==1){
				Map<String,Object> map =  new HashMap<String,Object>();
				map.put("colunm", cColunm[i]);//字段名
				map.put("after",list.get(0).get(eColunm[i]));
				if("status".equals(eColunm[i])){
					map.put("after","1".equals(list.get(0).get(eColunm[i]).toString())?"启用":"停用");
				}
				if("attribute".equals(eColunm[i])){
					map.put("after","1".equals(list.get(0).get(eColunm[i]).toString())?"省增补目录":"国家目录");
				}
				
				if(list.size()==1){
					map.put("red", "1");//是否变红加粗 1是 0 否
				}
				mapList.add(map);
			} else {
				Map<String,Object> map =  new HashMap<String,Object>();
				map.put("colunm", cColunm[i]);//字段名
				map.put("after",list.get(0).get(eColunm[i]));
				map.put("before",list.get(1).get(eColunm[i]));
				if("status".equals(eColunm[i])){
					map.put("after","1".equals(list.get(0).get(eColunm[i]).toString())?"启用":"停用");
					if(list.size()==1){
						map.put("before",null);
					}else{
						map.put("before","1".equals(list.get(1).get(eColunm[i]).toString())?"启用":"停用");
					}
				}
				if("attribute".equals(eColunm[i])){
					map.put("after","1".equals(list.get(0).get(eColunm[i]).toString())?"省增补目录":"国家目录");
					if(list.size()==1){
						map.put("before",null);
					}else{
						map.put("before","1".equals(list.get(1).get(eColunm[i]).toString())?"省增补目录":"国家目录");
					}
				}
				
				if(list.size()==1){
					map.put("red", "1");//是否变红加粗 1是 0 否
				}else{
					//判断修改后与修改前数据是否相等
					if(list.get(0).get(eColunm[i])!=null&&list.get(1).get(eColunm[i])!=null&&!list.get(0).get(eColunm[i]).toString().equals(list.get(1).get(eColunm[i]).toString())){
						map.put("red", "1");
					}else{
						map.put("red", "0");
					}
				}
				mapList.add(map);
			}
			
		}
		for(int i = 0;i<mapList.size();i++){//把要变红的放在list前面
			if("1".equals(mapList.get(i).get("red"))){
				dataList.add(mapList.get(i));
			}
		}
		for(int i = 0;i<mapList.size();i++){
			if("0".equals(mapList.get(i).get("red"))){
				dataList.add(mapList.get(i));
			}
		}
		request.setAttribute("dataList", dataList);
		request.setAttribute("list", list);
		return "/base/std/drugcata/stdDrugcatalogLogCompare";
	}
	
	
	
	
	/**
	 * @category 保存药品品规关联
	 * @author 周奇
	 * @date 2015年9月24日11:09:29
	 * @return Pagination
	 */
	@RequestMapping("/saveStdDrugCatalogDetail")
	@ResponseBody
	public Pagination saveStdDrugCatalogDetail(){
		Pagination page = new Pagination();
		try{
			String drugCataId = request.getParameter("drugCataId");
			String qualityspecClass = request.getParameter("qualityspecClass");
			String qualityspecIndex = request.getParameter("qualityspecIndex");
			BidDrugcatas  bidDrugcats = stdDrugcatalogManager.getBidDrugCatas(drugCataId);
			if(StringUtils.isNotBlank(qualityspecIndex)){
				bidDrugcats.setQualityspecIndex(Short.parseShort(qualityspecIndex));
			}
			if(StringUtils.isNotBlank(qualityspecClass)){
				bidDrugcats.setQualityspecClass(qualityspecClass);
			}
			stdDrugcatalogManager.updateBidDrugCatas(bidDrugcats);
			page.setSuccess(true);
			page.setMsg("保存成功！");
		}catch(Exception e){
			e.printStackTrace();
			page.setSuccess(false);
			page.setMsg("保存失败！");
		}
		return page;
	}
	
	/**
	 * @category 更改状态
	 * @author 周奇
	 * @date 2015年9月24日11:09:29
	 * @return Pagination
	 */
	@RequestMapping("/changeStatus")
	@ResponseBody
	public Pagination changeStatus(String param,String state){
		log.info("parm="+param+",state="+state);
		Pagination page = new Pagination();
		String[] overIds = param.split(",");
		short status =  Short.parseShort(state);
		try{
			for(int i= 0; i< overIds.length;i++){
				BidDrugcatas bidDrugcatas = stdDrugcatalogManager.getBidDrugCatas(overIds[i]);
				bidDrugcatas.setStatus(status);
				stdDrugcatalogManager.updateBidDrugCatas(bidDrugcatas);
			}
			page.setSuccess(true);
			page.setMsg("保存成功");
		}catch(Exception e){
			e.printStackTrace();
			page.setSuccess(false);
			page.setMsg("保存失败");
		}
		return page;
	}
	/**
	 * @category 获取bidDrugcatas数据
	 * @author 周奇
	 * @date 2015年9月24日11:09:29
	 * @return Pagination
	 */
	@RequestMapping("/getBidDrugcatas")
	@ResponseBody
	public BidDrugcatas getBidDrugcatas(String drugcatasId){
		return stdDrugcatalogManager.getBidDrugCatas(drugcatasId);
	}
	
	/**
	 * 
	 *@category 导出excel
	 *@author wangbing
	 *@date 2015年6月9日
	 *Pagination
	 */
	@RequestMapping("exportExcel")
	@ResponseBody
	public Pagination exportExcel(HttpServletResponse response,String fileName){
		//printParams();
		Pagination page = new Pagination();
		String qualityspecClass = request.getParameter("qualityspecClass");
		String qualityspecIndex = request.getParameter("qualityspecIndex");
		String qualityspecName = request.getParameter("qualityspecName");
		String qualityspecStatus = request.getParameter("qualityspecStatus");
		String drugcatalogId = request.getParameter("drugcatalogId");
		page.getConditions().put("drugcatalogId", drugcatalogId);
		if(StringUtils.isNotBlank(qualityspecClass)){
			page.getConditions().put("qualityspecClass", qualityspecClass.trim());
		}
		if(StringUtils.isNotBlank(qualityspecIndex)){
			page.getConditions().put("qualityspecIndex", qualityspecIndex.trim());
		}
		if(StringUtils.isNotBlank(qualityspecName)){
			page.getConditions().put("qualityspecName", qualityspecName.trim());
		}
		if(StringUtils.isNotBlank(qualityspecStatus)){
			page.getConditions().put("qualityspecStatus", qualityspecStatus.trim());
		}
		
		try {
			response.addHeader("Content-Disposition", "attachment;filename="+new String(fileName.getBytes("utf-8"),"iso8859-1")); 
			OutputStream os= new BufferedOutputStream(response.getOutputStream());  
			 response.setContentType("application/vnd.ms-excel;charset=utf-8");  
			 stdDrugcatalogManager.getDrugcatalogDetailNoPage(page);
			 String title = "药品目录详情";
			 String[] headers = {"分类名称","品种序号","通用名","剂型","规格","状态"};
			 String[] alias = {"qualityspecClass","qualityspecIndex","qualityspecName","formName","specName","status"};
			 ExcelUtil.exportExcel(page, os, title, headers, alias);
		} catch (Exception e) {
			page.setSuccess(false);
			e.printStackTrace();
		}
		return page;
	}
}
